package com.ruoyi.dl.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dl.domain.DlAbnormal;
import com.ruoyi.dl.service.IDlAbnormalService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 异常管理Controller
 * 
 * @author ruoyi
 * @date 2020-12-28
 */
@Controller
@RequestMapping("/dl/abnormal")
public class DlAbnormalController extends BaseController
{
    private String prefix = "dl/abnormal";

    @Autowired
    private IDlAbnormalService dlAbnormalService;

    @RequiresPermissions("dl:abnormal:view")
    @GetMapping()
    public String abnormal()
    {
        return prefix + "/abnormal";
    }

    /**
     * 查询异常管理列表
     */
    @RequiresPermissions("dl:abnormal:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DlAbnormal dlAbnormal)
    {
        startPage();
        List<DlAbnormal> list = dlAbnormalService.newSelectDlAbnormalList(dlAbnormal);
        return getDataTable(list);
    }

    /**
     * 导出异常管理列表
     */
    @RequiresPermissions("dl:abnormal:export")
    @Log(title = "异常管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DlAbnormal dlAbnormal)
    {
        List<DlAbnormal> list = dlAbnormalService.selectDlAbnormalList(dlAbnormal);
        ExcelUtil<DlAbnormal> util = new ExcelUtil<DlAbnormal>(DlAbnormal.class);
        return util.exportExcel(list, "abnormal");
    }

    /**
     * 新增异常管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存异常管理
     */
    @RequiresPermissions("dl:abnormal:add")
    @Log(title = "异常管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DlAbnormal dlAbnormal)
    {
        return toAjax(dlAbnormalService.insertDlAbnormal(dlAbnormal));
    }

    /**
     * 修改异常管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DlAbnormal dlAbnormal = dlAbnormalService.selectDlAbnormalById(id);
        mmap.put("dlAbnormal", dlAbnormal);
        return prefix + "/edit";
    }

    /**
     * 修改保存异常管理
     */
    @RequiresPermissions("dl:abnormal:edit")
    @Log(title = "异常管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DlAbnormal dlAbnormal)
    {
        return toAjax(dlAbnormalService.updateDlAbnormal(dlAbnormal));
    }

    /**
     * 删除异常管理
     */
    @RequiresPermissions("dl:abnormal:remove")
    @Log(title = "异常管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dlAbnormalService.deleteDlAbnormalByIds(ids));
    }
}
